package com.yhy.tradesystem;

import java.util.ArrayList;
import java.util.Date;

import com.yhy.tradesystem.util.Log;

public class TradeDataPak {
	/**
	 * 根据Const定义的名字或者技术指标数值挑出来，技术指标的名字与数据名用"/"分割
	 * */
	public float pickValueFromTradeDataPak(String valueName){
		if(Const.OPEN.equals(valueName)) return this.stockData.open;
		if(Const.CLOSE.equals(valueName)) return this.stockData.close;
		if(Const.HIGH.equals(valueName)) return this.stockData.high;
		if(Const.LOW.equals(valueName)) return this.stockData.low;
		
		String[] names = valueName.split("/");
		if(names!=null && names.length ==2){
			for(TechnicalAnalysisData ta:this.techDataList){
				if(ta.name.equals(names[0])){
					for (int i = 0; i < ta.dataNames.length; i++) {
						if(ta.dataNames[i].equals(names[1])){
							return ta.data[i];
						}
					}
				}
			}
		}
		
		Log.e("TradeDataPak", "pickValueFromTradeDataPak: 输入参数不能够正确解析！ %s", valueName);

		return -1f;
	}
	public static class StockData{
		public StockData(String stockName, float open, float close, float high,
				float low, long vol,Date date) {
			super();
			this.stockName = stockName;
			this.open = open;
			this.close = close;
			this.high = high;
			this.low = low;
			this.vol = vol;
			this.date =  date;
		}
		public final String stockName;
		public final float open;
		public final float close;
		public final float high;
		public final float low;
		public final long vol;
		public final Date date;
	}
	
	public static class TechnicalAnalysisData{
		public TechnicalAnalysisData(String name, 
				String[] parameterNames,float[] parameters,
				 String[] dataNames, float[] data) {
			super();
			this.name = name;
			this.parameters = parameters;
			this.parameterNames = parameterNames;
			this.dataNames = dataNames;
			this.data = data;
		}
		/**技术指标名称*/
		public final String name;
		
		/**技术指标参数列表*/
		public final float[] parameters;
		/**技术指标参数名称列表*/
		public final String[] parameterNames;
		
		/**技术指标数据名称列表*/
		public final String[] dataNames;
		/**技术指标数据*/
		public final float[] data;
		
	}
	
	public static class BuySellSignal{
		public static enum BuySellType{
			/**做多,开多仓*/
			BuySellOpen,
			/**做多,平多仓*/
			BuySellClose,
			/**做空,开仓*/
			SellShortOpen,
			/**做空,平仓*/
			SellShortClose,
		}
		public BuySellSignal(String stockName, long sum, BuySellType type,
				float price) {
			super();
			this.stockName = stockName;
			this.sum = sum;
			this.type = type;
			this.price = price;
		}
		/**操作的股票名称*/
		public final String stockName;
		/**操作的股票总数*/
		public final long sum;
		/**操作的股票类型*/
		public BuySellType type;
		/**交易价格*/
		public float price;
	}
	/**股票的基本价格走势信息，由数据源模块填写*/
	public StockData stockData;
	/**技术分析指标，由技术分析模块填写*/
	public ArrayList<TechnicalAnalysisData> techDataList;
	/**买卖信号与仓位，由策略模块与仓位管理模块填写*/
	public BuySellSignal signal;
	
	

}
